package com.es.pay.mailAndMsg;

import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import com.es.util.mail.SendMsg;
import com.es.util.msg.SendMessage;
import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.xwork.ActionSupport;

public class SendDoAction  extends ActionSupport implements ServletRequestAware{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	HttpServletRequest request;
	 
   public String execute()throws Exception{
	   
	   MailAndMsgBiz  manegeBiz= new MailAndMsgBiz();
	   String sendType = request.getParameter("sendType")==null?"":request.getParameter("sendType");
	   String yyyymm = request.getParameter("yyyymm")==null?"":request.getParameter("yyyymm");
	   String ctmId = request.getParameter("ctmId")==null?"":request.getParameter("ctmId");
	   String message ="";
	   if("".equals(ctmId)){
		   message = "员工编号不存在，请重新发送";
		   request.setAttribute("message", message);
		   return "success"; 
	   }
	   ArrayList<HashMap<String,String>> address = manegeBiz.getMailList(ctmId);
	   if("mail".equals(sendType)){//邮件
		   SendMsg.sendMailForSalary(address);
		   message = "通知邮件已发送,因网络延迟，可能稍后一段时间才能到达收件人";
	   }
	   if("msg".equals(sendType)){//短信
		   SendMsg.sendMsgForSalary(address);
		   message = "通知短信已发送,因网络延迟，可能稍后一段时间才能到达收信人";
	   }
	   if("all".equals(sendType)){//邮件和短信
		   SendMsg.sendMailForSalary(address);
		   SendMsg.sendMsgForSalary(address);
		   message = "通知已发送,因网络延迟，可能稍后一段时间才能到达收件人";
	   }
	   request.setAttribute("message", message);
	   return "success";
   }

   public void setServletRequest(HttpServletRequest request) {
	     this.request = request;
  }
}